local zhuangqi = fk.CreateSkill {
  name = "lingling__zhuangqi",
}

Fk:loadTranslationTable{
  ["lingling__zhuangqi"] = "壮气",
  [":lingling__zhuangqi"] = "准备阶段，你可以弃置一张红色非锦囊牌，然后令一名角色将手牌摸至四张，若弃置装备牌，结束阶段你也可以发动此技能。",

  ["#lingling__zhuangqi-invoke"] = "壮气：你可以弃置一张红色非锦囊牌，然后令一名角色将手牌摸至四张",
  ["#lingling__zhuangqi-choose"] = "壮气：令一名角色将手牌摸至四张",
}

zhuangqi:addEffect(fk.EventPhaseStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhuangqi.name) and
      (player.phase == Player.Start or (player.phase == Player.Finish and player:getMark("lingling__zhuangqi-turn") > 0)) and
      not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local card = room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = zhuangqi.name,
      pattern = ".|.|heart,diamond|.|.|^trick",
      prompt = "#lingling__zhuangqi-invoke",
      cancelable = true,
      skip = true,
    })
    if #card > 0 then
      event:setCostData(self, {cards = card})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = event:getCostData(self).cards[1]
    if Fk:getCardById(card).type == Card.TypeEquip then
      room:setPlayerMark(player, "lingling__zhuangqi-turn", 1)
    end
    room:throwCard(card, zhuangqi.name, player, player)
    if player.dead then return end
    local targets = table.filter(room.alive_players, function (p)
      return p:getHandcardNum() < 4
    end)
    if #targets > 0 then
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = zhuangqi.name,
        prompt = "#lingling__zhuangqi-choose",
        cancelable = false,
      })[1]
      to:drawCards(4 - to:getHandcardNum(), zhuangqi.name)
    end
  end,
})

return zhuangqi
